function getToken()
{
	var token = getCookie("token");

	// Verify token if it exists.
	if (token != null && token != "") {
		var response = getFromFlickrSynch("flickr.auth.checkToken", { }, false);
		if (response != null) {
			userId = response.auth.user.nsid;
			return token;
		}
	}

	// Reset token so new calls don't send old token.
	token = "";
	setCookie("token", token);

	// redirect to auth page if we don't even have a frob
	var frob = queryStringParams['frob'];
	if (frob == null) {
		window.location = "auth.php";
		return;
	}

	// get token from frob
	var response = getFromFlickrSynch("flickr.auth.getToken", {"frob": frob});
	if (response == null)
		return;

	// record new token
	token = response.auth.token._content;
	setCookie("token", token);

	// welcome user and redirect to non-frob'd page
	window.alert("Welcome, " + response.auth.user.username + ".");
	window.location = "./";
}
